# coding: utf-8

'''
Created on 27 avr. 2011

@author: shin
'''
import unittest
from business.Modele   import Modele
from business.Activite import Activite
from stub.Observer     import Observer
from business.Damier   import Damier 

class Test(unittest.TestCase):

    def setUp(self):
        self.modele = Modele()

    def tearDown(self):
        del self.modele



    def test_init_Activite(self):
        self.assertEqual(isinstance(self.modele._activite, Activite), True)

    def test_init_Elements(self):
        self.assertEqual(self.modele._elements, {})
        
    def test_nouveauCombat_initialisation_Damier(self):
        self.modele.addObserver(Observer())
        self.modele.nouveauCombat("niveau1")
        self.assertEqual(isinstance(self.modele._damierLink, Damier), True)

    def test_nouveauCombat_elements(self):
        self.modele.addObserver(Observer())
        self.modele.nouveauCombat("niveau1")
        self.assertEqual(self.modele._elements.has_key("A1"), True)
        self.assertEqual(self.modele._elements.has_key("A9"), False)
        self.assertEqual(self.modele._elements.has_key("K1"), False)
        self.assertEqual(self.modele._elements["A1"].nom, "A1")
        self.assertEqual(self.modele._elements["A1"].type, "Herbe")
        self.assertEqual(self.modele._elements["E1"].type, "Rocher")
        self.assertEqual(self.modele._elements["E2"].type, "Sable")
        self.assertEqual(self.modele._elements["A8"].type, "Eau")

    def test_notifyObserverZone_return_None(self):
        self.modele.addObserver(Observer())
        self.assertEqual(self.modele._notifyZone("nomZone", "texte"), None)

    def test_notifyObserverDamier_return_None(self):
        self.modele.addObserver(Observer())
        self.modele.nouveauCombat("niveau1")
        self.assertEqual(self.modele._notifyDamier(), None)

    def test_addObserver_return_None(self):
        self.assertEqual(self.modele.addObserver(Observer()), None)
        
    def test_addObserver_result(self):
        observer = Observer()
        self.modele.addObserver(observer)
        self.assertEqual(self.modele._observer, observer)

    def test_creerEquipe_return_None(self):
        self.modele.addObserver(Observer())
        self.assertEqual(self.modele.creerEquipe("Equipe1", "Equipe2"), None)
        
    def test_creerEquipe_elments_modif(self):
        self.modele.addObserver(Observer())
        self.modele.creerEquipe("Equipe1", "Equipe2")
        self.assertEqual(self.modele._elements.keys(),\
                         ['Asura', 'Shu', 'Mantas', 'Rankor'])
    
    def test_positionneElement(self):
        self.modele.addObserver(Observer())
        self.modele.nouveauCombat("niveau1")
        self.modele.creerEquipe("Equipe1", "Equipe2")
        self.modele.positionneElement("Asura", "A1")
        self.assertEqual(self.modele._damierLink.donnePosition("Asura"), "A1")

    def test_demandeCompetence_return_None(self):
        self.modele.addObserver(Observer())
        self.modele.nouveauCombat("niveau1")
        self.modele.creerEquipe("Equipe1", "Equipe2")
        self.modele.positionneElement("Shu", "A1")
        self.modele.lancePartie()
        self.assertEqual(self.modele.demandeCompetence('Mouvement'),
                         None )

    def test_demandeCompetence_modif_gameStatus(self):
        self.modele.addObserver(Observer())
        self.modele.nouveauCombat("niveau1")
        self.modele.creerEquipe("Equipe1", "Equipe2")
        self.modele.positionneElement("Shu", "A1")
        self.modele.lancePartie()
        self.assertEqual(self.modele._gameStatus.damier.cases["A1"],
                         ['marque_selected'] )

    def test_utiliseCompetence_return_None(self):
        self.modele.addObserver(Observer())
        self.modele.nouveauCombat("niveau1")
        self.modele.creerEquipe("Equipe1", "Equipe2")
        self.modele.positionneElement("Shu", "A1")
        self.modele.positionneElement("Rankor", "A2")
        self.modele.lancePartie()
        self.modele.demandeCompetence("Mouvement")
        self.modele._activite._prochaineAction = "Mouvement"
        self.assertEqual(self.modele.utiliseCompetence("A3"), None)

    def test_lancePartie_return_None(self):
        self.modele.addObserver(Observer())
        self.modele.nouveauCombat("niveau1")
        self.modele.creerEquipe("Equipe1", "Equipe2")
        self.modele.positionneElement("Shu", "A1")
        self.assertEqual(self.modele.lancePartie(), None)
        

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()